<template>
  <div class="app-container">
    <div class="filter-container">
      <statisSearchBar :start-date="searchForm.startDate" :end-date="searchForm.endDate" :showp-pf-channel="true" @transferFilter="handleFilter" />
    </div>
    <el-table v-loading="listLoading" :data="list" class="mt-10" border :cell-style="cellStyle">
      <el-table-column label="注册付费日期" prop="date" width="110px" align="center"></el-table-column>
      <el-table-column label="注册付费人数" prop="num" width="109px" align="center"></el-table-column>
      <el-table-column v-for="(day, index) in headList" :key="index" align="center" width="73px" :label="day+'留'">
        <template slot-scope="scope">
          <div class="pre-formatted">{{ scope.row.keep[day] }}</div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import StatisSearchBar from '@/components/StatisSearchBar'
import { getKeepRegRecharge } from '@/api/statis'

export default {
  name: 'KeepRegRecharge',
  components: { StatisSearchBar },
  data() {
    return {
      list: [],
      headList: [],
      total: 0,
      listLoading: false,
      searchForm: {
        startDate: new Date(Date.now() - 86400000 * 10),
        endDate: new Date()
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter(query) {
      this.searchForm = query
      this.getList()
    },
    async getList() {
      this.listLoading = true
      const res = await getKeepRegRecharge(this.searchForm)
      this.listLoading = false
      this.list = res.data.items
      this.headList = res.data.days
      this.total = res.data.total
    },
    cellStyle({ rowIndex, columnIndex }) {
      const colors = ['#fff', '#fafafa']
      return { background: colors[columnIndex % 2] }
    }
  }
}
</script>

<style>
  .pre-formatted {
    white-space: pre-wrap;
  }
  .cbg {
    background-color: bisque;
  }
</style>
